package com.huiminpay.transaction.message;

import com.alibaba.fastjson.JSON;
import com.huiminpay.paymentagent.api.dto.PaymentResponseDTO;
import com.huiminpay.paymentagent.api.dto.TradeStatus;
import com.huiminpay.transaction.api.TransactionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
@RocketMQMessageListener(topic = "TP_PAYMENT_RESULT", consumerGroup = "CID_ORDER_CONSUMER")
public class TransactionPayConsumer implements RocketMQListener<MessageExt> {

//    @Autowired
    @Resource
    TransactionService transactionService;

    @Override
    public void onMessage(MessageExt messageExt) {
        byte[] bytes = messageExt.getBody();
        String result_json = new String(bytes);
        //转为对象
        PaymentResponseDTO responseDTO = JSON.parseObject(result_json, PaymentResponseDTO.class);
        //取出商户订单号
        String outTradeNo = responseDTO.getOutTradeNo();
        //支付宝交易流水号
        String tradeNo = responseDTO.getTradeNo();
        //交易状态
        TradeStatus tradeState = responseDTO.getTradeState();


        //调交易服务更新订单信息
       // transactionService.updateOrderTradeNoAndTradeState(outTradeNo,tradeNo,);

    }
}
